package com.me.study.javaBasic.collection;

import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * HashMap 多线程安全测试
 *
 * @author ME
 */
public class TestHashMapSafe {

    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            new TestThread().start();
        }
    }

    public static class TestThread extends Thread {
        public static HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(2);
        public static AtomicInteger at = new AtomicInteger();

        public void run() {
            while (at.get() < 100000) {
                map.put(at.get(), at.get());
                at.incrementAndGet();
            }
        }
    }
}
